Creating labels for Machine Learning - Python Programming for Finance p. 11 - Key Error XOM_2d
Went through the tutorial for P11 Creating labels for Machine Learning and received a Key Error 'XOM_2d' here is my code down below. I am missing anything critical? I appreciate any help as I would like to continue with the Python lesson.
Code: [from collections import Counter import numpy as np import pandas as pd import pickle
for i in range(1, hm_days + 1): df['{}_{}d'.format(ticker, i)] = (df[ticker].shift(-1) - df[ticker]) / df[ticker]
df.fillna(0, inplace=True) return tickers, df
def buy_sell_hold(*args): cols = [c for c in args] requirement = 0.02 for col in cols: if col > requirement: return 1 # BUY if col < - requirement: return -1 # SELL return 0 # HOLD
X = df_vals.values y = df['{}_target'.format(ticker)].values
return X, y, df
extract_featuresets('XOM')]
You must be logged in to post. Please login or register an account.
The problem lies within the process_data_for_labels function, I was doing the same thing. You currently have df.fillna(0, inplace = True) and return tickers,df within your for loop.
-plantand000 4 years ago
You must be logged in to post. Please login or register an account.